WPF and Silverlight Edition Basic Library > Windows > Windows Features > Modal and Modeless Windows |
Dialog boxes are commonly used in applications to retrieve input from the user. In some applications a dialog box is used to prompt the user for input and once the application retrieves the input the dialog box is automatically closed or destroyed.
On the other hand, some applications use dialog boxes to display information while the user works in other windows. For example, when you check spelling in Microsoft Word a dialog box remains open so you can go through and edit your text in the document while the spell checker looks for the next misspelled word. To support the different ways applications use dialog boxes, C1Window supports two different types of dialog windows: modal and modeless dialog windows.
A modal dialog window is a child window that must be closed before the user can continue working on the current application. Typically modal dialog windows either take control of the entire system or application displaying them until they are closed. For example, you can use a modal dialog window to retrieve login information from a user before the user can continue working on an application. Modal windows are useful in presenting important information or requiring user interaction.
You can show the C1Window control as a modal dialog box using the ShowModal method:
Visual Basic |
Copy Code
|
---|---|
'The Show method is seen here in an If...Then...Else statement.
If showModal Then
wnd.ShowModal()
Else
wnd.Show()
End If
|
C# |
Copy Code
|
---|---|
//The Show method is seen here in an if...else statement. if (showModal) wnd.ShowModal(); else wnd.Show(); |
Setting the Modal Background Color
You can customize the color of your modal background using the ModalBackground property:
Visual Basic Copy Code Private Sub ShowDialog(ByVal sender As Object, ByVal e As RoutedEventArgs) Dim window = New C1Window() window.Content = New MyWindow() window.CenterOnScreen() Dim bgcol As New SolidColorBrush() bgcol.Color = Color.FromArgb(150, 255, 0, 0) window.ModalBackground = bgcol window.ShowModal() End Sub
C# Copy Code void ShowDialog(object sender, RoutedEventArgs e) { var window = new C1Window(); window.Content = new MyWindow(); window.CenterOnScreen(); SolidColorBrush bgcol = new SolidColorBrush(); bgcol.Color = Color.FromArgb(150, 255, 0, 0); window.ModalBackground = bgcol; window.ShowModal(); }
A modeless dialog window enables users to interact with other windows while the dialog window is present. Use this type of dialog window when the requested information is not necessary to continue. Modeless dialog windows do not keep the input focus so you can work on two applications at once.
A modeless dialog window is commonly used in menus and help systems where the user can use the dialog window and the application window concurrently. For example, a toolbar is a modeless dialog window because it can be detached from the application and the user can select items in the toolbar to apply features to the detached or separated application.
You can show the C1Window control as a modeless dialog box using the Show method:
Visual Basic |
Copy Code
|
---|---|
'The Show method is seen here in an If...Then...Else statement.
If showModal Then
wnd.ShowModal()
Else
wnd.Show()
End If
|
C# |
Copy Code
|
---|---|
//The Show method is seen here in an if...else statement. if (showModal) wnd.ShowModal(); else wnd.Show(); |